﻿using System.Security.Cryptography;
using System.Text;
using System.Web.Mvc;
using CatHouse.DAL;
using CatHouse.Lib;

namespace CatHouse.Controllers
{
    [LoginFilter]
    public class BaseAdminController : Controller
    {
        protected PetShopContext Db = new PetShopContext();

        protected string GetMd5Hash(string input = "")
        {
            HashAlgorithm md5Hash = new MD5CryptoServiceProvider();
            // Convert the input string to a byte array and compute the hash.
            var data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));

            // Create a new Stringbuilder to collect the bytes
            // and create a string.
            var sBuilder = new StringBuilder();

            // Loop through each byte of the hashed data
            // and format each one as a hexadecimal string.
            foreach (var t in data)
            {
                sBuilder.Append(t.ToString("x2"));
            }

            // Return the hexadecimal string.
            return sBuilder.ToString();
        }
    }
}